#ifndef __XKK_THREAD_H__
#define __XKK_THREAD_H__

#include "Noncopyable.hpp"
#include <functional>
#include <string>

using std::string;
using std::function;
namespace xkk
{

namespace current_thread
{
extern __thread const char* name;
}//end of namespace current_thread

class Thread
    :Noncopyable
{
    using ThreadCallback=function<void()>;
public:
    Thread(ThreadCallback && cb,const string &name=string()); 

    void start();
    void join();

    virtual ~Thread();
    pthread_t getThreadId() const { return _pthid; }
    string getThreadName() const { return _name; }
private:
    static void * threadFunc(void*);

private:
    pthread_t _pthid;
    string _name;
    ThreadCallback _cb;
    bool _isRunning;
};

}//end of namespace xkk
#endif
